#ifndef __U2DefaultWorkQueueStandard_H__
#define __U2DefaultWorkQueueStandard_H__

#include "../U2WorkQueue.h"


U2EG_NAMESPACE_BEGIN


/** Implementation of a general purpose request / response style background work queue.
@remarks
	This default implementation of a work queue starts a thread pool and 
	provides queues to process requests. 
*/
class _U2Share U2DefaultWorkQueue : public U2DefaultWorkQueueBase
{
public:

	U2DefaultWorkQueue(const U2String& name = U2StringUtil::BLANK);
	virtual ~U2DefaultWorkQueue(); 

	/// Main function for each thread spawned.
	virtual void _threadMain();

	/// @copydoc WorkQueue::shutdown
	virtual void shutdown();

	/// @copydoc WorkQueue::startup
	virtual void startup(bool forceRestart = true);

protected:
	/** To be called by a separate thread; will return immediately if there
		are items in the queue, or suspend the thread until new items are added
		otherwise.
	*/
	virtual void waitForNextRequest();

	/// Notify that a thread has registered itself with the render system
	virtual void notifyThreadRegistered();

	virtual void notifyWorkers();

	size_t mNumThreadsRegisteredWithRS;

	/// Init notification mutex (must lock before waiting on initCondition)
	U2_MUTEX(mInitMutex)
	/// Synchroniser token to wait / notify on thread init 
	U2_THREAD_SYNCHRONISER(mInitSync)

	U2_THREAD_SYNCHRONISER(mRequestCondition)
#if U2_THREAD_SUPPORT
	typedef vector<U2_THREAD_TYPE*>::type WorkerThreadList;
	WorkerThreadList mWorkers;
#endif
};


U2EG_NAMESPACE_END


#endif
